/**
 *       Copyright (c) 2012 Lukas Zaruba
 *
 *   This file is part of Robot Playground.
 *
 *   Robot Playground is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Robot Playground is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with Robot Playground. If not, see <http://www.gnu.org/licenses/>.
 */
package net.zarubsys.robotplayground.joystick;

import net.zarubsys.robotplayground.core.Environment;
import net.zarubsys.robotplayground.core.modules.AbstractModule;
import net.zarubsys.robotplayground.core.modules.EmptyModuleConfiguration;
import net.zarubsys.robotplayground.core.modules.annotations.Function;
import net.zarubsys.robotplayground.core.modules.annotations.Param;

/**
 * JoystickModule
 *
 * @author Lukas Zaruba, lukas.zaruba@gmail.com
 */
public class JoystickModule extends AbstractModule<JoystickDevice, EmptyModuleConfiguration> {
	
	public static final String ID = "joystickModule";
	
	private JoystickDevice device;

	@Override
	public void init(JoystickDevice device, EmptyModuleConfiguration configuration, Environment env) {
		this.device = device;
	}

	@Override
	public void close() {
		// ignore
	}

	@Override
	public String getId() {
		return ID;
	}

	@Override
	public String getRequiredDevice() {
		return JoystickDevice.ID;
	}
	
	@Function(description = "Returns position of the joystick on the x axis. Range of values is -32768 to 32767")
	public int getX() {
		return device.getX();
	}
	
	@Function(description = "Returns position of the joystick on the y axis. Range of values is -32768 to 32767")
	public int getY() {
		return device.getY();
	}
	
	@Function(description = "Returns state of the given button. 12 buttons (0..11) are supported. Returns true if pressed, false otherwise")
	public boolean getButton(@Param(name = "buttonId") Integer buttonId) {
		return device.getButton(buttonId);
	}

}

